package com.alipay.model;

import com.alipay.model.enums.ResponseCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Jun
 */
@Data
public class Response implements Serializable {
    /**
     * 本次请求流水号
     */
    private String requestNo;

    /**
     * 响应的状态码
     */
    private Integer code;

    /**
     * 响应的信息
     */
    private String msg;


    /**
     * 响应的数据
     */
    private Object data;


    public Response(String requestNo, ResponseCodeEnum codeEnum, Object data) {
        this.requestNo = requestNo;
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getMsg();
        this.data = data;
    }

    public Response(String requestNo, Integer code, String msg, Object data) {
        this.requestNo = requestNo;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static Response newResponse(String requestNo, ResponseCodeEnum codeEnum, Object data) {
        return new Response(requestNo, codeEnum, data);
    }


    public static Response newFailure(String requestNo, ResponseCodeEnum codeEnum) {
        return newResponse(requestNo, codeEnum, null);
    }

    public static Response newFailure(String requestNo, Integer code, String msg){
        return new Response(requestNo, code, msg, null);
    }


    public static Response newSuccess(String requestNo, Object data) {
        return newResponse(requestNo, ResponseCodeEnum.SUCCESS, data);
    }
}
